package com.zw.pdm.module.report.service;

import com.zw.pdm.constant.Constant;
import com.zw.pdm.entity.rep.Sheet;
import com.zw.pdm.module.report.mapper.ChangeMapper;
import com.zw.pdm.module.report.mapper.SheetMapper;
import com.zw.pdm.module.report.repository.SheetRepository;
import com.zw.pdm.module.system.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @Description:
 *
 * @Author: China.sgl
 * @Date: 2019/12/6 08:42
 */
@Service
@SuppressWarnings("all")
@Deprecated
public class ReportConfirmService {

    @Autowired
    private SheetMapper sheetMapper;
    @Autowired
    private SheetRepository sheetRepository;
    @Autowired
    private ChangeMapper changeMapper;
    @Autowired
    private LogService logService;


    /** 按条件查询计划单 */
    public List<Sheet> findWithReportConfirm(Sheet sheet) {
        return sheetMapper.findWithReportConfirm(sheet);
    }

    /** 确认 */
    @Transactional
    public int confirm(Integer id) {
        Sheet sheet = sheetRepository.getOne(id);
        sheet.setStatus(Constant.STATUS_CONFIRM);
//        if (sheet.getSheetType() == 1) {
            sheet.setMayChange(1);
//        }
        if (sheet.getSheetType() == 1) {
            return sheetMapper.insertResult(id);
        } else if (sheet.getSheetType() == 2) {
            return changeMapper.updateResultByChangeAfter(id);
        }
        logService.saveLog("确认计划单", "计划单ID：" + id);
        return 0;
    }

}
